package com.example.demo.Util;

import com.example.demo.annotation.FruitColor;
import com.example.demo.annotation.FruitName;
import com.example.demo.annotation.FruitProvider;
import com.example.demo.dao.Fruit;
import org.apache.catalina.LifecycleState;

import java.lang.reflect.Field;
import java.util.Map;

public class FruitAnnoUtil {

    public static void fruitAnnoUtil(Class<?> tClass) {

        // 反射
        Field[] fields = tClass.getDeclaredFields();


        for (Field field : fields) {
            // 判断当前注解是什么类型的
            if (field.isAnnotationPresent(FruitName.class)) {
                FruitName fruitName = field.getAnnotation(FruitName.class);
                String name = fruitName.fruitName();
                System.out.println("当前水果名称：" + name);
            } else if (field.isAnnotationPresent(FruitColor.class)) {
                FruitColor fruitColor = field.getAnnotation(FruitColor.class);
                FruitColor.Color color = fruitColor.fruitColor();
                System.out.println("当前水果颜色：" + color);
            } else if (field.isAnnotationPresent(FruitProvider.class)) {
                FruitProvider fruitProvider = field.getAnnotation(FruitProvider.class);
                int id = fruitProvider.id();
                String name = fruitProvider.name();
                String address = fruitProvider.address();
                System.out.println("供应商信息：" + "\n编号：" + id + "\n姓名：" + name + "\n供应地：" + address);
            }

        }

    }

}
